// components/video/index.js
import {
  getAllUserListDynamicApi
} from "../../../https/dynamic";
import {
  BASE_URL
} from '../../../constant/index'
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    BASE_URL,
    dynamicList: [],
    page: 1,
    limit: 5,
    total: 100,
    isHas: true,
    isLoading: false,
  },

  attached() {
    console.log(1)
    this.getAllDynamic()
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 获取动态数据
    async getAllDynamic() {
      const {
        total,
        page,
        limit,
        isLoading,
        dynamicList,
        isHas
      } = this.data
      console.log('关注发起请求1')
      console.log(page, limit, total, isLoading)
      if (isLoading) return
      if (!isHas) return
      this.setData({
        isLoading: true
      })

      const getRes = await getAllUserListDynamicApi({
        page,
        limit,
      })

      console.log(getRes)
      console.log("11111111+++++++++++")
      if (getRes.code == 200) {
        const newDynamicList = [...dynamicList, ...getRes.data.list]
        this.setData({
          dynamicList: newDynamicList,
          page: getRes.data.page + 1,
          total: getRes.data.total
        })
        if ((page) * limit >= total) {
          this.setData({
            isHas: false
          })
        } else {
          this.setData({
            isHas: true
          })
        }
      }
      console.log(this.data)
      this.setData({
        isLoading: false
      })
    },
    // 滚动到底部加载更多
  loadMore(e) {
    console.log('滚动到底部了')
    this.getAllDynamic()
  },
    // 跳转详情页面
    gotoDetail(e) {
      const docid = e.currentTarget.dataset.docid
      wx.navigateTo({
        url: '../../../pages/home/detail/index?docid=' + docid,
      })
    },
    // 跳转用户详情
    gotoMyDetail(e) {
      const docid = e.currentTarget.dataset.docid
      wx.navigateTo({
        url: '../../../pages/my/detail/index?docid=' + docid,
      })
    },
  }
})